#include "func.h"

typedef enum
{
    CD,LS,PUTS,GETS,REMOVE,PWD,MKDIR,RMDIR

} OrderType;

int whichOrder(char* orderList,int* orderflag,char* args)
{
    char* order = strtok(orderList," ");
    args = strtok(NULL," ");
    char buf[4];
    strncpy(buf,orderList,3);
    buf[3] = '\0'; 
    
    if(strcmp(order,"cd") == 0)
    {
        *orderflag = CD;
        printf("cd\n");
    }
    else if(strcmp(order,"ls") == 0)
    {
        *orderflag = LS;
        printf("ls\n");
    }
    else if(strcmp(order,"puts") == 0)
    {
        *orderflag = PUTS;
        printf("puts\n");
    }
    else if(strcmp(order,"gets") == 0)
    {
        *orderflag = GETS;
        printf("gets\n");
    }
    else if(strcmp(order,"remove") == 0)
    {
        *orderflag = REMOVE;
        printf("remove\n");
    }
    else if(strcmp(buf,"pwd") == 0)
    {
        *orderflag = PWD;
        printf("pwd\n");
    }
    else if(strcmp(order,"mkdir") == 0)
    {
        *orderflag = MKDIR;
        printf("mkdir\n");
    }
    else if(strcmp(order,"rmdir") == 0)
    {
        *orderflag = RMDIR;
        printf("rmdir\n");
    }
    else
    {
        printf("Illegal Order!\n");
        return -1;
    }

    return 0;
}

int execOrder_client(int orderflag,int netfd){
    switch(orderflag){
    case(CD):
        
        break;//cd 的具体函数
    case(LS):
        ls_client(path);
        break;
    case(PUTS):
        puts_client(netfd,path);
        break;
    case(GETS):
        gets_client(netfd,path);
        break;
    case(REMOVE):
        remove_client(path);
        break;
    case(PWD):
        pwd_client();
        break;
    case(MKDIR):
        mkdir_client();
        break;
    case(RMDIR):
        rmdir_client();
        break;
    }
    
    return 0;
}